package experiment;

import java.util.ArrayList;
import java.util.Hashtable;

import vo.User;
import Utils.Constants;
import Utils.FileUtils;
import Utils.MathUtils;

public class ReliabilityRanking {
	// 计算用户的信任值，倒序写入文件
	public static void computeUserIdReliability() {
		Hashtable<String, Double> userId_reliability = new Hashtable<String, Double>();
		ArrayList<Integer> followersCounts = new ArrayList<Integer>();// 所有人的followersCounts
		ArrayList<User> users = Init.loadUsers();
		for (User user : users)
			followersCounts.add(user.getFollowsCount());

		ArrayList<Double> followersCounts_norm = MathUtils.normalization(followersCounts);
		// 算每一个用户的信任值
		for (int i = 0; i < users.size(); i++) {
			User user = users.get(i);
			int verified = user.getVerified();
			double followerValue = followersCounts_norm.get(i);

			// 计算信任值
			double reliability = Constants.RELIA_FWEIGHT * followerValue + Constants.RELIA_VWEIGHT * verified;// TODO:计算retweet
			userId_reliability.put(user.getUserId(), reliability);
		}

		FileUtils.writeFileHashtable(userId_reliability, Constants.USERID_RELIABILITY_PATH, Constants.DESC);
	}

	public static void main(String args[]) {
		computeUserIdReliability();

	}
}
